package work.xiaohong.gupiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.xiaohong.gupiao.dao.ShangzhengMapper;
import work.xiaohong.gupiao.pojo.Shangzheng;
import work.xiaohong.gupiao.service.ShangzhengService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShangzhengServiceImpl implements ShangzhengService {

    @Autowired
    private ShangzhengMapper shangzhengMapper;


    /**
     * 条件+分页查询Shangzheng
     * @param shangzheng 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<Shangzheng> findPage(Shangzheng shangzheng, int page, int size){
        // 构建查询条件
        QueryWrapper<Shangzheng> queryWrapper = new QueryWrapper<Shangzheng>(shangzheng);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return shangzhengMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询Shangzheng
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Shangzheng> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return shangzhengMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法Shangzheng
     * @param shangzheng
     * @return
     */
    @Override
    public List<Shangzheng> findList(Shangzheng shangzheng){
        // 构建查询条件
        QueryWrapper<Shangzheng> queryWrapper = new QueryWrapper<Shangzheng>(shangzheng);
        // 查询数据
        return shangzhengMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除Shangzheng
     * @param id
     */
    @Override
    public void delete(Integer id){
        shangzhengMapper.deleteById(id);
    }

    /**
     * 根据ID修改Shangzheng
     * @param shangzheng
     */
    @Override
    public void update(Shangzheng shangzheng){
        shangzhengMapper.updateById(shangzheng);
    }

    /**
     * 增加Shangzheng
     * @param shangzheng
     */
    @Override
    public void add(Shangzheng shangzheng){
        shangzhengMapper.insert(shangzheng);
    }

    /**
     * 根据ID查询Shangzheng
     * @param id
     * @return
     */
    @Override
    public Shangzheng findById(Integer id){
        return  shangzhengMapper.selectById(id);
    }

    /**
     * 查询全部Shangzheng数据
     * @return
     */
    @Override
    public List<Shangzheng> findAll() {
        return shangzhengMapper.selectList(null);
    }
}
